package com.yuven.appframework.base

import android.app.Application
import com.tencent.mmkv.MMKV
import com.yuven.appframework.manager.AppActivitysManager
import com.yuven.appframework.manager.NetWorkManager
import com.yuven.appframework.util.CrashHandler
import com.yuven.appframework.util.DeviceIdUtil
import com.yuven.appframework.util.FileUtil
import com.yuven.appframework.util.NetWorkChangeObserveUtils
import com.yuven.appframework.widget.titlebar.DefaultTitleBarFactory
import com.yuven.appframework.widget.titlebar.TitleBarConfig
import com.yuven.baselib.utils.ToolsKit
import io.reactivex.plugins.RxJavaPlugins

object AppFrameWorkInit {

    @JvmStatic
    fun initFrameWork(mApplication: Application) {
        val rootDir: String = MMKV.initialize(mApplication)
        ToolsKit.init(mApplication)

        AppActivitysManager.getInstance().init(mApplication)

        DeviceIdUtil.init(mApplication)
        FileUtil.initDir(mApplication)
        CrashHandler.getInstance().init(mApplication, FileUtil.LOG_DIR)
        TitleBarConfig.setTitleBarFactory(DefaultTitleBarFactory())

        val instanceNet = NetWorkManager.getInstance()
        instanceNet.init(mApplication)
        instanceNet.registerListener(NetWorkChangeObserveUtils.netWorkConnectListener)

        RxJavaPlugins.setErrorHandler {
            it.printStackTrace()
        }
    }
}